package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.PerformBean;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2016/10/18 0018.
 */
public class PerformAdapter extends BaseAdapter {
    private Context context;
    private List<PerformBean> perList;
    ImageOptions options = new ImageOptions.Builder()
            //设置加载过程中的图片
            .setLoadingDrawableId(R.mipmap.ic_morentouxiang)
            //设置加载失败后的图片
            .setFailureDrawableId(R.mipmap.ic_morentouxiang)
            //设置使用缓存
            .setUseMemCache(true)
            //设置显示圆形图片
            .setCircular(true)
            //设置支持gif
            .setIgnoreGif(false)
            .build();
    public PerformAdapter(Context context, List<PerformBean> perList) {
        this.context = context;
        this.perList = perList;
    }

    @Override
    public int getCount() {
        return perList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        PerformViewHolder viewHolder = new PerformViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.perform_item, null);
            viewHolder.iv_head_perform = (ImageView) convertView.findViewById(R.id.iv_head_perform);
            viewHolder.tv_phone_perform = (TextView) convertView.findViewById(R.id.tv_phone_perform);
            viewHolder.tv_money_perform = (TextView) convertView.findViewById(R.id.tv_money_perform);
            viewHolder.tv_time_perform = (TextView) convertView.findViewById(R.id.tv_time_perform);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (PerformViewHolder) convertView.getTag();
        }

//        ImageLoader.getInstance().displayImage(perList.get(position).getHead(), viewHolder.iv_head_perform);
        viewHolder.tv_phone_perform.setText(perList.get(position).getPeoplePhone());
        viewHolder.tv_money_perform.setText("¥ " + perList.get(position).getExpenseMoney());
        viewHolder.tv_time_perform.setText(perList.get(position).getExpenseTime());
        x.image().bind(viewHolder.iv_head_perform,perList.get(position).getPeopleImg(),options);

        return convertView;
    }

    class PerformViewHolder {
        ImageView iv_head_perform;
        TextView tv_phone_perform;
        TextView tv_money_perform;
        TextView tv_time_perform;
    }
}
